package com.example;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Properties;

/**
 * 使用JDBC来删除tb_brand表中id为4的数据
 */

public class deleteTest {
    public static void main(String[] args) throws Exception {
        Properties prop=new Properties();
        prop.load(new FileInputStream("JDBC-Demo/src/druid.properties"));
        DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);
        Connection conn = dataSource.getConnection();
        int id =4;
        String sql="delete from tb_brand where id=?";

        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.setInt(1,id);
        int i = pstmt.executeUpdate();
        System.out.println(i>0);
    }
}
